package com.example.music_mediaplayer.service;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.example.music_mediaplayer.OnePiexlActivity;

/**
 * Created by quan on 2017/12/20.
 */

public class OnePxReceiver extends BroadcastReceiver {

    private static OnePxReceiver receiver;
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)){
            Intent it = new Intent(context, OnePiexlActivity.class);
            it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(it);
            Log.i("787878","1px--screen off-");
        } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)){
            context.sendBroadcast(new Intent("finish activity"));
            Intent main = new Intent(Intent.ACTION_MAIN);
            main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            main.addCategory(Intent.CATEGORY_HOME);//回到后台的操作
            context.startActivity(main);
            Log.i("787878","1px--screen on-");
        }
    }
}
